package com.nc.user.dao;

import com.nc.user.model.entity.FrmRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
public interface FrmRoleDao extends JpaRepository<FrmRole, String> {
    List<FrmRole> findByPermissionsRole_Code(String code);

    @Modifying
    @Query(value = "select b.* from frm_role as b " +
            "left join frm_users_frm_roles as c on b.id = c. frm_roles_id" +
            " where c.frm_users_id = ?1 ", nativeQuery = true)
    List<FrmRole> findByUserId(String id);

    FrmRole findByCode(String code);

    List<FrmRole> findByCodeIn(Set<String> codes);

    @Modifying
    @Query(value = "delete from frm_role_permissions_role where frm_roles_id = ?1 ", nativeQuery = true)
    Integer deleteByPer(String roleId);

    @Modifying
    @Query(value = "delete from frm_users_frm_roles where frm_roles_id = ?1 ", nativeQuery = true)
    Integer deleteByUsr(String roleId);
}
